<?php


use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;

class CreateChatTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('chat', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci','comment'=>'会话表']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('global_id', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一ID（uuid），一对一规则是2&3，小的user_id在前面。其他均为uuid'])
            ->addColumn('name', 'string', ['default' => '', 'limit' => 128, 'comment' => '名称'])
            ->addColumn('type', 'enum', ['values' => 'system,one2one,group,project', 'default' => 'one2one', 'comment' => '会话类型：system(系统), one2one(一对一), group（多人讨论组）, project'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '项目ID'])
            ->addColumn('link_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '关联外键ID'])
            ->addColumn('link_type', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '关联类型ID'])
            ->addColumn('public', 'integer', ['signed' => false, 'default' => 0, 'limit' => MysqlAdapter::INT_TINY, 'comment' => '公开状态，1：是，0：否'])
            ->addColumn('edited_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '修改者ID'])
            ->addColumn('edited_at', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '修改时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者ID'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间']);

        //执行创建
        $table->create();
    }
}
